package cn.milai.amtc.step2;

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

import cn.milai.amtc.Audio;

/**
 * 在新线程播放每一个音频 -> 线程大量创建销毁，资源消耗大
 */
public class AudioManager {

	private static Queue<Audio> audios = new ConcurrentLinkedQueue<Audio>();

	public static void add(Audio audio) {
		audios.add(audio);
	}

	public static void play() {
		if (!audios.isEmpty()) {
			new Thread(audios.poll()::play).start();
		}
	}
}
